package com.jfl.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Select;

import com.jfl.base.BaseMapper;
import com.jfl.model.SysMenu;

/**
 *  
 * @author  赵炎
 * @version  [V1.00, 2019年1月13日]
 * @since V1.00
 */
public interface SysMenuMapper extends BaseMapper<SysMenu>
{

    /** 
     * 根绝用户Id查询菜单
     * @param userId
     * @return
     */
    List<Long> selectMenusByUserId(Long userId);

    /** 
     * 根据角色Id查询
     * @param roleId
     * @return
     */
    List<String> selectMenuTree(Long roleId);

    @Select(" select m.permissions from tbl_sys_menu m left join tbl_sys_role_menu rm on rm.menu_id = m.id"
        + " left join tbl_sys_role r on r.id = rm.role_id"
        + " left join tbl_sys_user_role ur on ur.role_id = r.id"
        + " where ur.user_id = #{userId}")
    List<String> selectPermissionsByUserId(Long userId);

    @Select("select count(1) from tbl_sys_menu where parent_id = #{parentId}")
    int selectCountByParentId(Long parentId);

}
